home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Inne
/
Gry
/
Carnage_Contest
/
scripts
/
CC Original
/
weapons
/
Blow Gun.lua
< prev
next >
Wrap
Text File
|
2010-08-31
|
5KB
|
156 lines
--------------------------------------------------------------------------------
-- Weapon Blow Gun + Projectile Dart
-- Original Carnage Contest Weapon
-- Script by DC, September 2009, www.UnrealSoftware.de
--------------------------------------------------------------------------------
-- Setup Tables
if cc==nil then cc={} end
cc.blowgun={}
cc.blowgun.dart={}
-- Load & Prepare Ressources
cc.blowgun.gfx_wpn=loadgfx("weapons/blowgun.bmp") -- Weapon Image
sethandle(cc.blowgun.gfx_wpn,4,14)
cc.blowgun.gfx_icon=loadgfx("weapons/blowgunicon.bmp") -- Weapon Icon
setmidhandle(cc.blowgun.gfx_icon)
cc.blowgun.gfx_pro=loadgfx("weapons/dart.bmp") -- Projectile Image
setmidhandle(cc.blowgun.gfx_pro)
cc.blowgun.sfx_attack=loadsfx("arrow_shoot.ogg") -- Attack Sound
cc.blowgun.sfx_impact=loadsfx("arrow_impact.ogg") -- Impact Sound
--------------------------------------------------------------------------------
-- Weapon: Blow Gun
--------------------------------------------------------------------------------
cc.blowgun.id=addweapon("cc.blowgun","Blow Gun (Tranquilizer)",cc.blowgun.gfx_icon,0) -- Add Weapon (0 uses)
cc.blowgun.ammo=1 -- 1 Dart
function cc.blowgun.draw() -- Draw
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
drawinhand(cc.blowgun.gfx_wpn,4,-4)
-- HUD Crosshair
if cc.blowgun.ammo-weapon_shots>0 then
hudcrosshair(4,-1)
end
end
function cc.blowgun.attack(attack) -- Attack
-- Decrement timer
if weapon_timer>0 then
weapon_timer=weapon_timer-1
end
-- Attack
if weapon_shots<cc.blowgun.ammo and weapon_timer<=0 and attack==1 then
-- No more weapon switching!
useweapon(0)
-- Reset Timer
weapon_timer=25
-- Attack
playsound(cc.blowgun.sfx_attack)
weapon_shots=weapon_shots+1
id=createprojectile(cc.blowgun.dart.id)
projectiles[id]={}
-- Ignore collision with current player at beginning
projectiles[id].ignore=playercurrent()
-- Set initial position of projectile
projectiles[id].x=getplayerx(0)+(4*getplayerdirection(0))-math.sin(math.rad(getplayerrotation(0)))*10.0
projectiles[id].y=getplayery(0)-4+math.cos(math.rad(getplayerrotation(0)))*10.0
-- Set speed of projectile
projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*14.0
projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*14.0
-- Initial movement
projectiles[id].x=projectiles[id].x-projectiles[id].sx*0.3
projectiles[id].y=projectiles[id].y-projectiles[id].sy*0.3
for i=1,1,1 do
if cc.blowgun.dart.move(id)==1 then
break
end
end
-- Effects
recoil(3)
-- End Turn
if (weapon_shots>=cc.blowgun.ammo) then
endturn()
end
end
end
--------------------------------------------------------------------------------
-- Projectile: Dart
--------------------------------------------------------------------------------
cc.blowgun.dart.id=addprojectile("cc.blowgun.dart") -- Add Projectile
function cc.blowgun.dart.draw(id) -- Draw
-- Setup draw mode
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
setscale(1,1)
-- Calculate projectile rotation
setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
-- Draw projectile
drawimage(cc.blowgun.gfx_pro,projectiles[id].x,projectiles[id].y)
-- Draw arrow if out of Screen
outofscreenarrow(projectiles[id].x,projectiles[id].y)
end
function cc.blowgun.dart.update(id) -- Update
-- Wind + Gravity influence on speed
projectiles[id].sx=projectiles[id].sx+getwind()*0.1
projectiles[id].sy=projectiles[id].sy+getgravity()*1.5
-- Move
cc.blowgun.dart.move(id)
end
function cc.blowgun.dart.move(id)
rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
-- Move (in substep loop for optimal collision precision)
msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/2)
msubx=projectiles[id].sx/msubt
msuby=projectiles[id].sy/msubt
for i=1,msubt,1 do
projectiles[id].x=projectiles[id].x+msubx
projectiles[id].y=projectiles[id].y+msuby
-- Collision
if collision(col2x2,projectiles[id].x+math.sin(math.rad(rot))*4,projectiles[id].y-math.cos(math.rad(rot))*4)==1 then
if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
if playercollision()~=0 then
-- Sleep!
playsound(sfx_splatter3)
playerstate(playercollision(),state_sleeping,1)
elseif terraincollision()==1 then
-- Draw dart in terrain
terrainimage(cc.blowgun.gfx_pro,projectiles[id].x,projectiles[id].y,0,rot)
end
-- Effects
playsound(cc.blowgun.sfx_impact)
particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*4,projectiles[id].y-math.cos(math.rad(rot))*4)
particlefadealpha(0.006)
-- Free projectile
freeprojectile(id)
return 1
end
else
projectiles[id].ignore=0
end
-- Water
if (projectiles[id].y)>getwatery()+5 then
-- Effects
particle(p_waterhit,projectiles[id].x,projectiles[id].y)
if math.random(1,2)==1 then
playsound(sfx_hitwater2)
else
playsound(sfx_hitwater3)
end
-- Free projectile
freeprojectile(id)
return 1
end
end
-- Scroll to projectile
scroll(projectiles[id].x,projectiles[id].y)
end